package edu.ntu.im.p2ptrade.msg.handle;

import java.util.Date;

import edu.ntu.im.p2ptrade.P2PTrade;
import edu.ntu.im.p2ptrade.entity.Dialog;
import edu.ntu.im.p2ptrade.entity.DialogRepository;
import edu.ntu.im.p2ptrade.msg.PMessage;
import net.jxta.endpoint.Message;

public class GenericDialogHandle implements PMessageHandle {

	public void handle(Message msg) {
		String content = msg.getMessageElement(P2PTrade.getInstance().getAppName(), PMessage.CONTENT).toString(); 
		String peer =  msg.getMessageElement(P2PTrade.getInstance().getAppName(), PMessage.PEER).toString();
		Dialog dialog = new Dialog();
		dialog.setFrom(peer);
		dialog.setContent(content);
		dialog.setDate(new Date());
		DialogRepository.getInstance().addDialog(dialog);
	}



}
